<?php
	$mysql_username = "root";
	$mysql_password = "nitrkl123";
	$mysql_host = "127.0.0.1";
	$mysql_database = "video_tracking";
	ini_set('session.save_path', '/tmp');
	session_start();
	
	$link = mysql_connect($mysql_host, $mysql_username, $mysql_password) or die("Could not connect to database:".mysql_error());
	mysql_select_db($mysql_database, $link) or die("Could not set database");
	
	$uname = $_POST['uname'];
	$uname = mysql_real_escape_string($uname);
	$passwd = $_POST['passwd'];
	$passwd = mysql_real_escape_string($passwd);
	
	$select_query = sprintf("SELECT * FROM users WHERE (username='%s' AND password='%s')", $uname, $passwd);
	$select_result = mysql_query($select_query);
	if(!$select_result) {
		$message = 'Invalid query: '.mysql_error()."\n";
		$message.= 'Whole Query: '.$select_query;
		die($message);
	}
	if(mysql_num_rows($select_result) == 1) {
		//Set session variable
		$row = mysql_fetch_assoc($select_result);
		$_SESSION['uname'] = $row['username'];
		header("Location: choose_video.php");
	} else {
		print "User was not found. Check your username and password";
	}
?>